from ronglian_sms_sdk import SmsSDK
from flask import current_app
import time

class SdkCode():
    sdk = None

    def __init__(self):
        acc_id = current_app.config.get('RONGLIAN_ACC_ID')
        acc_Token = current_app.config.get('RONGLIAN_ACC_TOKEN')
        app_id = current_app.config.get('RONGLIAN_APP_ID')
        self.sdk = SmsSDK(acc_id,acc_Token,app_id)

    def fa_code(self,mobile,code):
        time.sleep(5)
        from app import app
        with app.app_context():
            tid = current_app.config.get('RONGLIAN_TID')
            code_time = current_app.config.get('RONGLIAN_TIME')
            dap = self.sdk.sendMessage(tid,mobile,datas=(code,code_time*60))
            print(dap)

            if dap:
                return True
            else:
                return False